<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <link href="./static/plugins/bootstrap/bootstrap.min.css" rel="stylesheet">
    <link href="./static/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="./static/css/font-awesome.min.css" rel="stylesheet">
    <link href="./static/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="./static/plugins/blueimp/blueimp-gallery.min.css" rel="stylesheet">
    <link href="./static/plugins/ladda/ladda-themeless.min.css" rel="stylesheet">
    <link href="./static/css/animate.css" rel="stylesheet">
    <link href="./static/css/style.css" rel="stylesheet">

    <script type="text/javascript" src="./static/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="./static/plugins/bootstrap/bootstrap.min.js"></script>
</head>
<body class="fixed-sidebar no-skin-config full-height-layout">
<div id="wrapper" v-cloak>
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="sidebar-collapse">
            <ul class="nav metismenu" id="side-menu">
                <li class="nav-header">
                    <div class="dropdown profile-element">
                        <span class="img-thumb"><strong class="font-bold">{{user.company}}</strong></span>
                        <a href="javascript:">
                            <span class="clear">
                                <span class="block m-t-xs"> <strong class="font-bold">{{type[user.type]}}</strong></span>
                            </span>
                        </a>
                    </div>
                </li>
                <li>
                    <a href="/home.html"><i class="fa fa-home"></i> <span class="nav-label">个人中心</span></a>
                </li>
                <li>
                    <a href="#"><i class="fa fa-info-circle"></i> <span class="nav-label">基本信息</span><span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li><a href="user.html">个人信息</a></li>
                        <li><a href="verify.html">账号认证</a></li>
                        <li><a href="finance.html">财务明细</a></li>
                        <li v-if="user.is_root>0"><a href="employee.html">员工账号</a></li>
                        <li><a href="pwd.html">修改密码</a></li>
                        <li><a href="address.html">收货地址</a></li>
                    </ul>
                </li>
                <li v-if="user.type!=2">
                    <a href="#"><i class="fa fa-th-large"></i> <span class="nav-label">询价</span> <span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li><a href="inquiry_list.html">询价单</a></li>
                        <li><a href="enquiry.html">我要询价</a></li>
                    </ul>
                </li>
                <li v-else>
                    <a href="#"><i class="fa fa-th-large"></i> <span class="nav-label">报价</span> <span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li><a href="inquiry_list_supply.html">未报价</a></li>
                        <li><a href="offer_sheet.html">已报价</a></li>
                    </ul>
                </li>
                <li>
                    <a href="index.html"><i class="fa fa-first-order"></i> <span class="nav-label">订单管理</span> <span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li><a href="order_list.html">订单列表</a></li>

                    </ul>
                </li>
                <li>
                    <a onclick="logout()"><i class="fa fa-sign-out"></i> <span class="nav-label">退出登录</span></a>
                </li>
            </ul>
        </div>
    </nav>
    <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <a class="navbar-minimalize minimalize-styl-2 btn btn-success" href="#"><i class="fa fa-bars"></i> </a>
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li class="m-r">
                        <span class="m-r-sm text-danger font-bold welcome-message" id="nav-title">{{user.name}}&nbsp;</span><span>{{user.company}}&nbsp;{{user.zone}}</span>
                    </li>
                    <li class="dropdown m-r">
                        <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#" aria-expanded="false">
                            <i class="fa fa-bell"></i> <span class="label label-danger" v-if="msgbox.total">{{msgbox.total}}</span>
                        </a>
                        <ul class="dropdown-menu dropdown-alerts">
                            <li v-if="msgbox.daifahuo">
                                <a href="javascript:parent.document.getElementById('main').src='order_list.html?order_status=200'">
                                    <div>
                                        <i class="fa fa-envelope fa-fw"></i> 您有<strong>{{msgbox.daifahuo}}</strong>个待发货订单
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.daifahuo"></li>
                            <li v-if="msgbox.daifukuan">
                                <a href="javascript:parent.document.getElementById('main').src='order_list.html?order_status=100'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.daifukuan}}</strong>个待付款订单
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.daifukuan"></li>
                            <li v-if="msgbox.daishouhuo">
                                <a href="javascript:parent.document.getElementById('main').src='order_list.html?order_status=300'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.daishouhuo}}</strong>个订单待收货
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.daishouhuo"></li>
                            <li v-if="msgbox.baojiazhong && user.type==1">
                                <a href="javascript:parent.document.getElementById('main').src='inquiry_list.html?status=100'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.baojiazhong}}</strong>个报价中询价单
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.baojiazhong && user.type==1"></li>
                            <li v-if="msgbox.daibaojia">
                                <a href="javascript:parent.document.getElementById('main').src='inquiry_list_supply.html'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.daibaojia}}</strong>个待报价询价单
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.daibaojia"></li>
                            <li v-if="msgbox.weitongguo">
                                <a href="javascript:parent.document.getElementById('main').src='offer_sheet.html'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.weitongguo}}</strong>个报价未通过
                                    </div>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a onclick="logout()">
                            <i class="fa fa-sign-out"></i> 安全退出
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
        <!--面包屑-->
        <div class="row wrapper border-bottom white-bg p-h-sm">
            <div class="col-lg-10">
                <ol class="breadcrumb">
                    <li class="active">
                        <strong>订单支付</strong>
                    </li>
                </ol>
            </div>
        </div>

        <div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
            <div class="row">
                <div class="col-md-6 col-md-offset-3">
                    <div class="ibox">
                        <div class="ibox-title">
                            <h5>订单支付</h5>
                        </div>
                        <div class="ibox-content">
                            <span>订单金额</span>
                            <h2 class="font-bold"><i class="fa fa-cny"></i>&nbsp;<strong class="text-danger">{{order.amount}}</strong></h2>
                            <hr>
                            <div class="pay-select">
                                <div id="weixin" class="border pointer" data-type="wxpayWeb">
                                    <img src="http://mallscsj.oss-cn-beijing.aliyuncs.com//upload/return_goods/20181115/HHah7C7j7f.png">
                                    微信支付
                                </div>
                                <div id="ali" class="border border-danger pointer" data-type="alipayWeb">
                                    <img src="http://mallscsj.oss-cn-beijing.aliyuncs.com//upload/return_goods/20181115/kM7R5KBBZ6.png">
                                    支付宝
                                </div>
                            </div>
                            <hr>
                            <div class="m-t-sm text-center">
                                <a href="javascript:history.back();" class="btn btn-white btn-sm m-r-lg"> 取消</a>
                                <a @click="payOrder()" class="btn btn-primary btn-sm"><i class="fa fa-shopping-cart"></i> 立即支付</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal fade" id="wx-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">{{payType}}扫码支付</h4>
                </div>
                <div class="modal-body">
                    <p class="text-center">
                        <img :src="'http://qr.zy52.cn/?data='+qrcode">
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="./static/plugins/toastr/toastr.min.js"></script>
<script type="text/javascript" src="./static/plugins/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="./static/js/slimscroll.min.js"></script>
<script type="text/javascript" src="./static/js/metisMenu.js"></script>
<script type="text/javascript" src="./static/js/inspinia.js"></script>
<script type="text/javascript" src="./static/plugins/ladda/spin.min.js"></script>
<script type="text/javascript" src="./static/plugins/ladda/ladda.min.js"></script>
<script type="text/javascript" src="./static/plugins/ladda/ladda.jquery.min.js"></script>
<script type="text/javascript" src="./static/js/vue.min.js"></script>
<script type="text/javascript" src="./static/js/main.js"></script>
<script>
    var vm = new Vue({
        el: '#wrapper',
        data: {
            user: {},
            order: {},
            qrcode: '',
            timmer: 0,
            type: {"1": "修理厂", "2": "配件商", "3": "保险公司"},
            payType: '微信',
            msgbox: {},
        },
        methods: {
            getData: function (instance) {
                $.ajax({
                    type: 'POST',
                    url: api + 'user/ordersDetail',
                    data: {order_no: getUrlParam('order_no')},
                    success: function (data) {
                        checkToken(data);
                        if (data.ret == 0) {
                            if (data.data.status > 100) {
                                location.href = '/order_detail.html?order_no=' + data.data.order_no;
                            }
                            instance.order = data.data;
                        }
                    }
                });
            },
            payOrder: function () {
                var method = $('.border.border-danger').data('type');
                vm.payType = method == 'alipayWeb' ? '支付宝' : '微信';
                var url = api + 'index/' + method;
                var re_url = location.origin + '/order_detail.html?order_no=' + vm.order.order_no;
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: {order_no: vm.order.order_no, return_url: re_url},
                    success: function (data) {
                        if (data.ret == 0) {
                            vm.qrcode = data.data;
                            $('#wx-modal').modal('show');
                            vm.lunch();
                        } else {
                            toastr.error(data.msg);
                        }
                    }
                });
            },
            payOrderBak: function () {
                var method = $('.border.border-danger').data('type');
                var url = api + 'index/' + method;
                var re_url = location.origin + '/order_detail.html?order_no=' + vm.order.order_no;
                if (method == 'alipayWeb') {
                    var form = document.createElement('form');
                    form.method = 'post';
                    form.action = url;
                    var return_url = document.createElement('input');
                    return_url.type = 'hidden';
                    return_url.name = 'return_url';
                    return_url.value = re_url;
                    var order_no = document.createElement('input');
                    return_url.type = 'hidden';
                    order_no.name = 'order_no';
                    order_no.value = vm.order.order_no;
                    form.append(return_url);
                    form.append(order_no);
                    document.body.append(form);
                    form.submit();
                } else {
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: {order_no: vm.order.order_no, return_url: re_url},
                        success: function (data) {
                            if (data.ret == 1) {
                                vm.qrcode = data.data;
                                $('#wx-modal').modal('show');
                                vm.lunch();
                            }
                        }
                    });
                }
            },
            lunch: function (stop) {
                if (stop) {
                    clearInterval(vm.timmer);
                    return;
                }
                vm.timmer = setInterval(function () {
                    $.ajax({
                        type: 'POST',
                        url: api + 'index/checkPayResult',
                        data: {order_no: vm.order.order_no},
                        success: function (data) {
                            if (data.ret == 0) {
                                parent.socket.send(JSON.stringify({action: "newOrder", wsmem: data.data.wsmem, order_no: data.data.order_no, orders_id: vm.order.id}));
                                location.href = '/order_detail.html?order_no=' + vm.order.order_no;
                            }
                        }
                    });
                }, 1000);
            }
        },
        created: function () {
            this.user = getItem('info');
            this.getData(this);
            var self = this;
            $.ajax({
                type: 'POST',
                url: api + 'user/msgNum',
                dataType: 'json',
                success: function (data) {
                    if (data.ret == 0) {
                        self.msgbox = data.data;
                    }
                },
            });
        },
        mounted: function () {
            var instance = this;
            $('.pay-select > div').on('click', function () {
                $(this).addClass('border-danger').siblings().removeClass('border-danger');
            });
            $('#wx-modal').on('hidden.bs.modal', function () {
                instance.lunch(true);
            });
        }
    });

</script>
</body>
</html>
